package org.sunspotworld.demo;

import java.awt.*;
import javax.swing.*;

public class ListDndD {
    ListTransferHandler arrayListHandler = new ListTransferHandler();

    private JPanel getContent() {
        JPanel panel = new JPanel(new GridLayout(1,0));
        panel.add(getSensorListComponent());
        panel.add(getEmptyListComponent());
        return panel;
    }

    private JScrollPane getEmptyListComponent() {
        DefaultListModel model = new DefaultListModel();

        JList list = new JList(model);
        list.setName("Configure List");
        list.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
        //list.setTransferHandler(arrayListHandler);
        list.setDragEnabled(true);
        return new JScrollPane(list);

    }

    private JScrollPane getSensorListComponent() {
        DefaultListModel model = new DefaultListModel();

        //TODO to update to include all the sensors. 
        model.addElement("acc-X");
        model.addElement("acc-Y");
        model.addElement("acc-Z");
        
        JList list = new JList(model);
        list.setName("Sensor List");
        list.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
        list.setTransferHandler(arrayListHandler);
        list.setDragEnabled(true);
        return new JScrollPane(list);
    }

    public static void createAndShowGUI() {
        JFrame f = new JFrame();
        f.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
        f.getContentPane().add(new ListDndD().getContent());
        f.setSize(400,200);
        f.setLocationRelativeTo(null);
        f.setVisible(true);
    }
}